const util = require('../../../../common/util/util.js')

Page({
    data: {
        xPageReady : true,
        xEmail:{
          icon:"https://7633-v3-92ah4-1300208657.tcb.qcloud.la/static/xx.png?sign=cf044cdc226203e09e737a5d60de2f89&t=1650266326",
          title:"信箱（来信服务）",
          path:'../../email/list/index'
        },
        xEmailcount:0,
        xList:[{
          icon:"https://7633-v3-92ah4-1300208657.tcb.qcloud.la/static/xpl.png?sign=89af6233e90282db797507d647fc508b&t=1650266312",
          title:"新评论",
          count:0,
          type:2,
          id:200001,
          path:'../../comment/index/index'
        },{
          icon:"https://7633-v3-92ah4-1300208657.tcb.qcloud.la/static/dz.png?sign=66138c4602358d5876fba21b39deb83b&t=1650263555",
          title:"点赞",
          count:0,
          path:'../../comment/index/index',
          type:2,
          id:200002
        }
        ,{
          icon:"https://7633-v3-92ah4-1300208657.tcb.qcloud.la/static/plhf.png?sign=e8cf7697666b36257f246c703abdb6fb&t=1650266302",
          title:"评论回复",
          count:0,
          path:''
        }]
    },

    onShow: function () {
        this.xInit()
    },
    xToemail:function(){
      wx.cloud.callFunction({
        name: 'station_message',
        data: {
          action: "set_to_read"
        }
      }).then(res => {
        wx.navigateTo({
          url: '../../email/list/index'
        })
        
      })
    },
    tonext: function ( e ){
      
      wx.cloud.callFunction({
        name: 'station_message',
        data: {
          action: "set_to_read"
        }
      }).then(res => {
        let type =e.currentTarget.dataset.type;
        let id =e.currentTarget.dataset.id
        wx.navigateTo({
          url: '../../comment/index/index?type='+type+'&id='+id,
        })
        
      })


    },
    xInit: async function () {
			let that = this
			that.setData({
        list:[]
      })
      await wx.cloud.callFunction({
        name: 'consulting_message',
        data: {
            action: "get_new_feedback_of_letter"
        }
      }).then(res => {
          console.log("邮件" , res.result)
          that.setData({
            xEmailcount: res.result
          })
      })

      wx.cloud.callFunction({
        name: 'station_message',
        data: {
          action: "get_unread_message_list_count",
        }
      }).then(res => {
        for(let index in res.result.list){
          if(res.result.list[index]._id=='200001'){
            that.setData({
              ['xList[0].count']:res.result.list[index].num
            })
          }else if(res.result.list[index]._id=='200002'){
            that.setData({
              ['xList[1].count']:res.result.list[index].num
            })
          }
        }
      })
      that.setData({
        xPageReady : false
      })
    },
})